package com.flyco.modules.oms.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flyco.modules.oms.entity.*;
import com.flyco.modules.oms.mapper.*;
import com.flyco.modules.oms.service.IOmsJddjOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 京东到家订单表
 * @Author: flyco
 * @Date:   2021-08-24
 * @Version: V1.0
 */
@DS("store")
@Service
public class OmsJddjOrderServiceImpl extends ServiceImpl<OmsJddjOrderMapper, OmsJddjOrder> implements IOmsJddjOrderService {

	@Autowired
	private OmsJddjOrderMapper omsJddjOrderMapper;
	@Autowired
	private OmsJddjOrderProductMapper omsJddjOrderProductMapper;
	@Autowired
	private OmsJddjOrderInvoiceMapper omsJddjOrderInvoiceMapper;
	@Autowired
	private OmsJddjOrderDiscountMapper omsJddjOrderDiscountMapper;
	@Autowired
	private OmsJddjOrderBillMapper omsJddjOrderBillMapper;
	@Autowired
	private OmsJddjBalanceBillMapper omsJddjBalanceBillMapper;

	@Override
	@Transactional
	public void saveMain(OmsJddjOrder omsJddjOrder, List<OmsJddjOrderProduct> omsJddjOrderProductList,
						 List<OmsJddjOrderInvoice> omsJddjOrderInvoiceList,
						 List<OmsJddjOrderDiscount> omsJddjOrderDiscountList,List<OmsJddjBalanceBill> omsJddjBalanceBillList) {
		omsJddjOrderMapper.insert(omsJddjOrder);
		for(OmsJddjOrderProduct entity:omsJddjOrderProductList) {
			//外键设置
			entity.setJddjOrderId(omsJddjOrder.getId());
			omsJddjOrderProductMapper.insert(entity);
		}
		for(OmsJddjOrderInvoice entity:omsJddjOrderInvoiceList) {
			//外键设置
			entity.setJddjOrderId(omsJddjOrder.getId());
			omsJddjOrderInvoiceMapper.insert(entity);
		}
		for(OmsJddjOrderDiscount entity:omsJddjOrderDiscountList) {
			//外键设置
			entity.setJddjOrderId(omsJddjOrder.getId());
			omsJddjOrderDiscountMapper.insert(entity);
		}
		for(OmsJddjBalanceBill entity:omsJddjBalanceBillList){
			//外键设置
			entity.setJddjOrderId(omsJddjOrder.getId());
			omsJddjBalanceBillMapper.insert(entity);
		}
	}
	
}
